import time
from tinyshop.common.Set_up import Setup
class Tinyshop_Login:
    def __init__(self):
        self.driver=Setup().driver
    #  登录
    def login(self,username,password):
        self.driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[2]/ul/li[7]/a[1]').click()
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div/form/ul/li[1]/input').clear()
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div/form/ul/li[1]/input').send_keys(username)
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div/form/ul/li[2]/input').clear()
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div/form/ul/li[2]/input').send_keys(password)
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div/form/ul/li[4]/button').click()
        return self.driver

    #创建登录成功断言函数
    def assert_succ(self,expect):
        if expect in self.driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[2]/ul/li[7]').text:
            print('pass')
        else:
            print('fail')
        self.driver.close()
    #创建登录失败断言
    def assert_fail(self,expect):
        if expect in self.driver.find_element_by_xpath('/html/body/div[2]/div/div/form/ul/li[2]/label').text:
            if expect =='':
                expect='no input email'
            print('pass login fail reason is %s'%expect)
        else:
            print('fail')
        self.driver.close()


